#! /bin/sh
# 请在此输入您想执行的脚本
echo 'Hello Gitee!'
echo "-----------------脚本开始-----------------"
docker_image="${GITEE_DOCKER_IMAGE}"

echo "镜像地址${docker_image}"

if [ ! $docker_image]; then
    echo "镜像地址使用默认地址"
    docker_image='registry.cn-hangzhou.aliyuncs.com/liuhaojie/tangtuweb:latest'
fi
#${docker_image:='registry.cn-hangzhou.aliyuncs.com/liuhaojie/tangtu:latest'}
echo "最终镜像地址${docker_image}"

filedir=/root/tangtuweb
if [ -d "$filedir" ]; then
    echo "文件夹已存在：${filedir}"
else
    echo "文件夹不已存在，需要创建文件夹：${filedir}"
    mkdir $filedir
fi

file=/root/tangtuweb/docker-compose.yml
if test -f "$file"; then
    echo "文件已存在：${file}，开始删除"
    rm $file -r -f
fi

cat >"${file}" <<EOF
version: '3.3'
services:
    tangtuweb:
        restart: always
        ports:
            - '8090:80'
        container_name: tangtuweb
        image: ${docker_image}
EOF

docker-compose -f ${file} down
docker-compose -f ${file} up -d

echo "-----------------脚本结束-----------------"

